package com.internship.javawebinternship.myUtils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class MD5Encrypt {

    public static final String KEY_MD5 = "MD5";

    public static String encryptMD5(String data) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
        md5.update(data.getBytes(StandardCharsets.UTF_8));
        byte[] encrypt = md5.digest();
        String result = "";
        //将byte[]转换为String
        for (int i = 0; i < encrypt.length; i++) {
            result += Integer.toHexString((0x000000ff & encrypt[i]) | 0xffffff00).substring(6);
        }
        return result;
    }

}